package main;

import java.util.LinkedList;
import java.util.Queue;

/**
 * 统计过去3000ms内的请求次数，ping（t）在t时刻发出一个请求
 * 1 1
 */
public class RecentAverage {
    private Queue<Integer> times;
    private int windowSize;
    public RecentAverage(){
        times = new LinkedList<>();
        windowSize = 3000;
    }

    public int ping(int t){
        times.offer(t);
        while (times.peek() + windowSize < t){
            times.poll();
        }
        return times.size();
    }

    public static void main(String[] args) {
        RecentAverage recentAverage = new RecentAverage();
        System.out.println( recentAverage.ping(1));
        System.out.println(recentAverage.ping(10));
        System.out.println(recentAverage.ping(3001));
        System.out.println(recentAverage.ping(3002));
    }

}
